<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(to right, #ff9a9e, #fad0c4);
            height: 100vh;
            margin: 0;
            display: flex;
            flex-direction: column;
        }
        .navbar {
            display: flex;
            justify-content: space-between;
            background-color: #fff;
            padding: 10px 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .navbar a {
            text-decoration: none;
            color: #ff6f61;
            font-weight: bold;
            transition: color 0.3s;
            cursor: pointer;
            margin-left: 20px;
        }
        .navbar a:hover {
            color: #ff4b47;
        }
        .container {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        .book-display {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 20px;
        }
        .book {
            width: 200px;
            padding: 20px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        .book img {
            width: 100%;
            height: auto;
            border-radius: 5px;
        }
        .book-title {
            color: #ff6f61;
            margin: 10px 0;
            font-size: 18px;
            font-weight: bold;
        }
        .book-author, .book-price {
            color: #333;
            margin: 5px 0;
        }
        .pay-now {
            margin-top: 10px;
            padding: 10px;
            background-color: #ff6f61;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .pay-now:hover {
            background-color: #ff4b47;
        }
        .qr-code {
            display: none;
            margin-top: 20px;
        }
    </style>
    <script>
        function payNow(bookId, bookName, bookPrice) {
            const buyerName = prompt("请输入购买者姓名:");
            const address = prompt("请输入收货地址:");
            const phone = prompt("请输入手机号:");
            if (buyerName && address && phone) {
                fetch('${pageContext.request.contextPath}/checkout', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    body: 'bookId=' + bookId + '&bookName=' + bookName + '&bookPrice=' + bookPrice + '&buyerName=' + encodeURIComponent(buyerName) + '&address=' + encodeURIComponent(address) + '&phone=' + encodeURIComponent(phone)
                })
                .then(response => response.text())
                .then(data => {
                    document.getElementById('qr-code-' + bookId).style.display = 'block';
                });
            }
        }

        function confirmPayment(bookId) {
            alert("购买成功!");
            document.getElementById('qr-code-' + bookId).style.display = 'none';
        }
    </script>
    
</head>
<body>
<div class="navbar">
    <div>
        <a href="${pageContext.request.contextPath}/home">主页</a>
    </div>
    <div>
        <a href="${pageContext.request.contextPath}/logout">登出</a>
    </div>
</div>
<div class="container">
    <div class="book-display">
        <div class="book">
            <img src="${pageContext.request.contextPath}/images/23441278_0.jpg" alt="Book Image">
            <div class="book-title">《曹操》</div>
            <div class="book-author">作者: 宗文涛</div>
            <div class="book-price">价格: ¥50</div>
            <button class="pay-now" onclick="payNow('23441278_0', '《曹操》', '50')">立即付款</button>
            <div id="qr-code-23441278_0" class="qr-code">
                <img src="${pageContext.request.contextPath}/images/qr-code.png" alt="QR Code">
                <button onclick="confirmPayment('23441278_0')">已支付</button>
            </div>
        </div>
<%--       ---------------------------------------------------------------------------------------------%>
        <div class="book">
            <img src="${pageContext.request.contextPath}/images/23441278_1.jpg" alt="New Book Image">
            <div class="book-title">《新书籍》</div>
            <div class="book-author">作者: 新作者</div>
            <div class="book-price">价格: ¥60</div>
            <button class="pay-now" onclick="payNow('23441278_1', '《新书籍》', '60')">立即付款</button>
            <div id="qr-code-23441278_1" class="qr-code">
                <img src="${pageContext.request.contextPath}/images/qr-code.png" alt="QR Code">
                <button onclick="confirmPayment('23441278_1')">已支付</button>
            </div>
        </div>
<%--       ---------------------------------------------------------------------------------------------%>
        <div class="book">
            <img src="${pageContext.request.contextPath}/images/23441278_1.jpg" alt="New Book Image">
            <div class="book-title">《新书籍》</div>
            <div class="book-author">作者: 新作者</div>
            <div class="book-price">价格: ¥60</div>
            <button class="pay-now" onclick="payNow('23441278_2', '《新书籍111》', '6110')">立即付款</button>
            <div id="qr-code-23441278_2" class="qr-code">
                <img src="${pageContext.request.contextPath}/images/qr-code.png" alt="QR Code">
                <button onclick="confirmPayment('23441278_2')">已支付</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
